package io.renren.modules.work.service.impl;

import io.renren.common.utils.R;
import io.renren.modules.work.entity.ScReportEntity;
import io.renren.modules.work.service.ScReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.work.dao.ScReportdtlDao;
import io.renren.modules.work.entity.ScReportdtlEntity;
import io.renren.modules.work.service.ScReportdtlService;


@Service("scReportdtlService")
public class ScReportdtlServiceImpl extends ServiceImpl<ScReportdtlDao, ScReportdtlEntity> implements ScReportdtlService {

    @Autowired
    private ScReportService scReportService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ScReportdtlEntity> page = this.page(
                new Query<ScReportdtlEntity>().getPage(params),
                new QueryWrapper<ScReportdtlEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public R getReportsByNo(String reportno) {
        QueryWrapper<ScReportEntity> scReportEntityQueryWrapper = new QueryWrapper<>();
        scReportEntityQueryWrapper.eq("reportno",reportno);
        ScReportEntity scReportEntity = scReportService.getOne(scReportEntityQueryWrapper);
        if(scReportEntity==null){
            throw new RuntimeException("数据异常");
        }
        QueryWrapper<ScReportdtlEntity> scReportdtlEntityQueryWrapper = new QueryWrapper<>();
        scReportdtlEntityQueryWrapper.eq("reportid",scReportEntity.getReportid());
        List<ScReportdtlEntity> scReportdtlEntities = baseMapper.selectList(scReportdtlEntityQueryWrapper);
        return R.ok().put("list",scReportdtlEntities);
    }

}